package four;

import java.util.Arrays;
import java.util.Scanner;

public class test11079 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k =scanner.nextInt();
        int[] stone = new int[n+1];
        for (int i = 1; i <= n; i++) {
            stone[i]= scanner.nextInt();
        }
        System.out.println(stoneMin(n,k,stone)+" "+stoneMax(n,k,stone));
    }

    private static int stoneMin(int n, int k, int[] stone) {
        int[] s = new int[n+k];
        for (int i = 1; i <=n ; i++) {
            s[i]=stone[i];
        }
        while(n%(k-1)!=1){
            n++;
            s[n]=0;
        }
        int j = (n-1)/(k-1);
        int[] s1 = new int[j+1];
        for (int i = 0; i < j; i++) {
            Arrays.sort(s,1,n+1);
            for(int t = 1;t<k;t++){
                s[1+(k-1)*i]=s[1+(k-1)*i+t]+s[1+(k-1)*i];
                s[1+(k-1)*i+t]=-1;
            }
            s1[i+1]=s[1+(k-1)*i];
        }
       int sum=0;
        for (int i = 1; i <=j ; i++) {
            sum=s1[i]+sum;
        }
        return sum;
    }

    private static int stoneMax(int n, int k, int[] stone) {
        Arrays.sort(stone);
        int[] s = new int[n];
        int sum = stone[n]+stone[n-1];
        s[n-1]=sum;
        for (int i = n-2; i >=1 ; i--) {
            sum=sum+stone[i];
            s[i]=sum;
        }
        sum=0;
        for (int i = 1; i <=n-1 ; i++) {
            sum=s[i]+sum;
        }
        return sum;
    }
}
